package criptosuma.formulation.constraints;
  
import java.util.ArrayList;
import java.util.List;

import es.deusto.ingenieria.is.csp.formulation.Constraint;
import es.deusto.ingenieria.is.csp.formulation.Variable;

public class AllDif extends Constraint<Integer> 
{

	public AllDif(String name, List<Variable<Integer>> variables) 
	{
		super(name, variables);
	}

	@Override
	public boolean isSatisfied(Variable<Integer> variable, Integer valueToAssign) 
	{
		ArrayList<Variable<Integer>> variables = (ArrayList<Variable<Integer>>) getVariables();
		for (int i = 0; i < variables.size(); i++) 
		{
			if(!variables.get(i).getName().equals(variable.getName()) 
					&& variables.get(i).hasValue() 
					&& variables.get(i).getValue().equals(valueToAssign))
			{
				return false;
			}
		}
		return true;
	}
	
	@Override
	public String toString()
	{
		String n = null;
		ArrayList<Variable<Integer>> variables = (ArrayList<Variable<Integer>>) getVariables();
		for (int i = 0; i < variables.size(); i++) 
		{
			n += "Nombre variable: " + variables.get(i).getName() + ", Valor: " + variables.get(i).getValue() + ".\n";
		}
		return n;
	}
}
